package csu.edu.flatprogram.controller.front;

import csu.edu.flatprogram.common.CommonResponse;
import csu.edu.flatprogram.entity.Order;
import csu.edu.flatprogram.persistence.AccountMapper;
import csu.edu.flatprogram.persistence.CartMapper;
import csu.edu.flatprogram.service.OrderService;
import csu.edu.flatprogram.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    Order order;
    @Autowired
    AccountMapper accountMapper;
    @Autowired
    CartMapper cartMapper;
    //根据用户ID寻找订单
    @GetMapping("/{userId}/order")
    @ResponseBody
    public CommonResponse<List<OrderVO>> getOrdersByUserId(@PathVariable("userId") String userId){
        return orderService.getOrderByUserId(userId);
    }
    //根据订单ID寻找订单
    @GetMapping("/{orderId}/orders")
    @ResponseBody
    public CommonResponse<OrderVO> getOrdersByOrderId(@PathVariable("orderId") String orderId) {
        return orderService.getOrdersByOrderId(orderId);
    }
    //添加订单
    @PostMapping("/add")
    @ResponseBody
    public CommonResponse<OrderVO> addOrder(@RequestBody OrderVO orderVO){
        return orderService.addOrder(orderVO);
    }

    //删除订单
    @DeleteMapping("/delete")
    @ResponseBody
    public CommonResponse<OrderVO> deleteOrder(@RequestBody OrderVO orderVO){return orderService.deleteOrder(orderVO);}

}
